﻿using System;
using System.Linq;
using System.Text;
using DevExpress.Xpo;
using DevExpress.ExpressApp;
using System.ComponentModel;
using DevExpress.ExpressApp.DC;
using DevExpress.Data.Filtering;
using DevExpress.Persistent.Base;
using System.Collections.Generic;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;

namespace RX2_Office.Module.BusinessObjects
{
    [NavigationItem ("Work Order")]
    [DefaultClassOptions]
    //[ImageName("BO_Contact")]
    //[DefaultProperty("DisplayMemberNameForLookupEditorsOfThisType")]
    [DefaultListViewOptions(MasterDetailMode.ListViewAndDetailView, false, NewItemRowPosition.None)]
    //[Persistent("DatabaseTableName")]
    // Specify more UI options using a declarative approach (https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument112701).
    public class RepackDistributor : XPObject
    { // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument113146.aspx).
        public RepackDistributor(Session session)
            : base(session)
        {
        }
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            // Place your initialization code here (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112834.aspx).
        }
        //private string _PersistentProperty;
        //[XafDisplayName("My display name"), ToolTip("My hint message")]
        //[ModelDefault("EditMask", "(000)-00"), Index(0), VisibleInListView(false)]
        //[Persistent("DatabaseColumnName"), RuleRequiredField(DefaultContexts.Save)]
        //public string PersistentProperty {
        //    get { return _PersistentProperty; }
        //    set { SetPropertyValue("PersistentProperty", ref _PersistentProperty, value); }
        //}

        //[Action(Caption = "My UI Action", ConfirmationMessage = "Are you sure?", ImageName = "Attention", AutoCommit = true)]
        //public void ActionMethod() {
        //    // Trigger a custom business logic for the current record in the UI (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112619.aspx).
        //    this.PersistentProperty = "Paid";
        //}

        string phone;
      //  string eZip;
        State repackDistributorState;
        string repackDistributorZipCode;
        string repackDistributorCity;
        string repackDistributorAddress;
        string repackDistributorName;

        [Size(SizeAttribute.DefaultStringMappingFieldSize)]
        public string RepackDistributorName
        {
            get => repackDistributorName;
            set => SetPropertyValue(nameof(RepackDistributorName), ref repackDistributorName, value);
        }


        [Size(SizeAttribute.DefaultStringMappingFieldSize)]
        public string RepackDistributorAddress
        {
            get => repackDistributorAddress;
            set => SetPropertyValue(nameof(RepackDistributorAddress), ref repackDistributorAddress, value);
        }


        [Size(SizeAttribute.DefaultStringMappingFieldSize)]
        public string RepackDistributorCity
        {
            get => repackDistributorCity;
            set => SetPropertyValue(nameof(RepackDistributorCity), ref repackDistributorCity, value);
        }


        [Size(SizeAttribute.DefaultStringMappingFieldSize)]
        public string RepackDistributorZipCode
        {
            get => repackDistributorZipCode;
            set => SetPropertyValue(nameof(RepackDistributorZipCode), ref repackDistributorZipCode, value);
        }
        [NonPersistent]

        [Size(SizeAttribute.DefaultStringMappingFieldSize)]
        public string CityStateZip
        {
            get => RepackDistributorCity + ". " + repackDistributorState.StateCode + " " + RepackDistributorZipCode;

        }
        
        [Size(12)]
        public string Phone
        {
            get => phone;
            set => SetPropertyValue(nameof(Phone), ref phone, value);
        }

        [Association("State-RepackDistributors")]
        public State RepackDistributorState
        {
            get => repackDistributorState;
            set => SetPropertyValue(nameof(RepackDistributorState), ref repackDistributorState, value);
        }

        [Association("RepackDistributor-RepackItems")]
        public XPCollection<RepackItems> RepackItems
        {
            get
            {
                return GetCollection<RepackItems>(nameof(RepackItems));
            }
        }


    }
}